package mapreduce;

/**
*	The class to keep track of column sizes
*	and their specific information
*/


public class ColumnGrp
{
	public static int getNumberOfGroups() {
		return DataToPass.cases;
	}
	
	/*
	 * This is including the left boundary of the column Group
	 */
	public static double getLeftBoundryOfGroup(int group) {
		int noOfGroups = getNumberOfGroups();
		assert((group <= noOfGroups) && (group > 0));
		return Math.max(0, ((group-1)/(double)noOfGroups) -DataToPass.lmax/2);
	}
	
	/*
	 * This is including the right boundary of the column Group
	 */
	public static double getRightBoundryOfGroup(int group) {
		int noOfGroups = getNumberOfGroups();
		assert((group <= noOfGroups) && (group > 0));
		return Math.min(1, ((group)/(double)noOfGroups) +DataToPass.lmax/2);
	}
	
	public static int getMainGroup(Point p) {
		return Math.min(((int)(p.getx()* getNumberOfGroups())+1), getNumberOfGroups());
	}
	
	public static int getSecondryGroup(Point p) {
		int grp = getMainGroup(p);
		return getSecondryGroup(p, grp);
	}
	
	public static int getSecondryGroup(Point p, int mainGrp) {
		if(mainGrp!=1 && p.getx() - getLeftBoundryOfGroup(mainGrp) < DataToPass.lmax)
			return mainGrp - 1;
		else
			if(mainGrp!=getNumberOfGroups() && getRightBoundryOfGroup(mainGrp) - p.getx() < DataToPass.lmax)
				return mainGrp + 1;
		return -1;
	}

	public static double getActualLeftBoundary(int group) {
		return (group-1)/(double)DataToPass.cases;
	}

	public static double getActualRightBoundary(int group) {
		return group/(double)DataToPass.cases;
	}
	
	public static boolean inActualBoundary(Point point, int group) {
		return ((point.getx()>=getActualLeftBoundary(group) &&
				point.getx()<getActualRightBoundary(group)) || 
				(point.getx()==DataToPass.MAX_LIMIT &&
				group == DataToPass.cases));
		
	}
	
}